package com.java.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.java.model.*;
import com.java.service.*;
import com.java.utils.CommonUtils;
import com.java.utils.JsonBody;
import com.java.utils.PageList;
import com.java.utils.ResponseUtil;;

@RestController
@RequestMapping("/thingtype2")
public class ThingType2Controller {
	private ThingType2Service thingtype2Service;

	public ThingType2Service getThingType2Service() {
		return thingtype2Service;
	}

	@Autowired
	public void setThingType2Service(ThingType2Service thingtype2Service) {
		this.thingtype2Service = thingtype2Service;
	}

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;


	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("add")
	public JsonBody add(@RequestBody ThingType2 nt) {

			int r=0;
			if(nt.getId()==0)
				r = thingtype2Service.Add(nt);
			else
				r=thingtype2Service.Edit(nt);
			if(r>0)
				return Util.SetMap("保存成功", true);
			else
				return
						Util.SetMap("保存失败", false);
	}

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("list")
	public JsonBody list() {
		return Util.SetData(thingtype2Service.Get());
	}

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("getbyid")
	public JsonBody getbyid(int id) {
		return Util.SetData(thingtype2Service.GetByID(id));
	}


	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("del")
	public JsonBody Del(int id) {
		if(thingtype2Service.Del(id)>0)
			return Util.SetMap("删除成功", true);
		else
			return Util.SetMap("删除失败", false);
	}

}
